
package jp.isisredirect.adk;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

abstract public class UsbAccessoryActivity extends Activity {
    static final String TAG = "UsbAccessoryActivity";
    static final private boolean DBG = true;

    static private Intent mIntent = null;
    static private boolean mLaunched = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (DBG)
            Log.d(TAG, "onCreate");
        if (!isLaunched()) {
            mIntent = getIntentToLaunch();

            mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            try {
                startActivity(mIntent);
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
            }
            setLaunched(true);
        }
        finish();
    }

    abstract public Intent getIntentToLaunch();

    public static boolean isLaunched() {
        return mLaunched;
    }

    public static void setLaunched(boolean mLaunched) {
        UsbAccessoryActivity.mLaunched = mLaunched;
    }

}
